package com.yao.ro.controller;

import java.util.Objects;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yao.common.bean.PageQueryBean;
import com.yao.common.helper.ValidateHelper;
import com.yao.common.resp.ApiResponse;
import com.yao.ro.entity.dto.EquipmentDto;
import com.yao.ro.entity.vo.EquipmentVo;
import com.yao.ro.service.EquipmentService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * 装备制作表 Controller
 *
 * @author autoCode
 * @version 1.0.0-SNAPSHOT
 * @date 2020-04-22
 */
@Api(tags = "装备制作管理")
@RestController
@RequestMapping(value = "/equipment")
@Slf4j
public class EquipmentController {

    @Autowired
    private EquipmentService equipmentService;

    @ApiOperation(value = "新增装备制作", notes = "新增装备制作")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ApiResponse<Object> add(@RequestBody EquipmentDto model) {

        ValidateHelper.validateNull(model, new String[] {"goodsId", "cost"});

        equipmentService.add(model);

        return ApiResponse.success();
    }

    @ApiOperation(value = "修改装备制作", notes = "修改装备制作")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ApiResponse<Object> update(@RequestBody EquipmentDto model) {
        return ApiResponse.success();
    }

    @ApiOperation(value = "删除装备制作", notes = "逻辑删除装备制作")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    public ApiResponse<Object> deleteById(@PathVariable("id") Integer id) {
        return ApiResponse.success();
    }

    @ApiOperation(value = "详情", notes = "详情")
    @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
    public ApiResponse<Object> get(@PathVariable("id") Integer id) {

        ValidateHelper.validateId(id);

        return ApiResponse.success(equipmentService.getById(id));

    }

    @ApiOperation(value = "装备列表(分页)", notes = "装备列表")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public ApiResponse<IPage<EquipmentVo>> list(@RequestBody PageQueryBean<EquipmentDto> queryBean) {

        if (Objects.isNull(queryBean.getData())) {
            queryBean.setData(new EquipmentDto());
        }

        return ApiResponse.success(equipmentService.page(new Page<>(queryBean.getCurrent(), queryBean.getSize()), queryBean.getData()));
    }

}